<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
var maxDistance = function(nums1, nums2) {
    let i = 0, j = 0;
    let n = nums1.length, m = nums2.length;
    let res = 0;
    while(i < n && j < m) {
        if (nums1[i] <= nums2[j]) {
            res = Math.max(res, j - i);
            j++;
        } else {
            i++;
        }
    }
    return res;
};
  </script>
</body>
</html>